package com.zw.april14thh.controller;

import com.zw.april14thh.entity.AdminUser;
import com.zw.april14thh.service.AdminUserService;
import com.zw.april14thh.service.BusinessService;
import com.zw.april14thh.vo.AjaxResult;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/system")
public class SystemController {

    @Autowired
    BusinessService businessService;
    @Autowired
    AdminUserService adminUserService;

    /**
     * 查询对应窗口全部的排队信息
     * @return
     */
    @GetMapping("/all")
    public AjaxResult getAll(int pageNum,int pageSize,Integer adminId){

        //查询管理员  支持的类型 的全部排队信息（不包含废弃的信息）
        AjaxResult success = businessService.getAllByAdminUser( pageNum, pageSize,adminId);
        return success;
    }

    /**
     * 呼叫用户
     * @return
     */
    @GetMapping("/call")
    public AjaxResult call(String id,Integer adminId){

        //先查询数据库是否为为排队状态 1

        //根据排队id 更改业务表状态为 2(正在办理)然后给业务表添加窗口号

        return businessService.callMemberUser(id, adminId);
    }

    /**
     * 结束办理
     * @return
     */
    @GetMapping("/doOver")
    public AjaxResult doOver(String id){

        //根据业务id 更改业务表状态为 3(办理结束)

        return businessService.doOverBusiness(id);
    }

    /**
     * 取消办理
     * @return
     */
    @GetMapping("/cancel")
    public AjaxResult cancel(String id){

        //根据排队id 更改排队表状态为 0(取消排队)

        return businessService.cancelBussiness(id);
    }

    @PostMapping("/login")
    public AjaxResult login(String username,String password,boolean rememberMe) {
        adminUserService.login(username,password,rememberMe);
        return AjaxResult.success();
    }


    @GetMapping("/logout")
    public AjaxResult logout(){

        Subject subject = SecurityUtils.getSubject();

        subject.logout();

        return AjaxResult.success();
    }
    @GetMapping("/changeWindow")
    public AjaxResult changeWindowId(Integer windowId,Integer adminId) {
        return adminUserService.changeWindowId(windowId, adminId);
    }
}
